﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ETypeMailInfoForm.aspx.cs"
    Inherits="FX.CC.Andon.WebSite.BasicDataManage.ETypeMailInfoForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../lib/boot.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" method="post">
    <fieldset style="border: solid 1px #aaa; padding: 5px;">
        <legend>邮箱信息</legend>
        <div style="padding-left: 11px; padding-bottom: 5px;">
            <table style="table-layout: fixed; float: left">
                <tr>
                    <td style="width: 80px;" align="left">
                        邮箱地址：
                    </td>
                    <td style="width: 300px;" align="left">
                        <input name="MailAddr" class="mini-textbox" vtype="email" emptytext="请输入邮箱地址" onenter="onKeyEnter"
                            style="width: 300px;" />
                    </td>
                </tr>
            </table>
        </div>
    </fieldset>
    <fieldset style="border: solid 1px #aaa; padding: 5px; height: 300px;">
        <legend>邮箱地址信息</legend>
        <div class="mini-toolbar" style="padding: 2px; border-bottom: 0;">
            <table style="width: 100%;">
                <tr>
                    <td style="width: 100%;" align="center">
                        <a class="mini-button" iconcls="icon-add" onclick="add();" plain="true">添加</a> <a
                            class="mini-button" iconcls="icon-remove" onclick="removeRow()" plain="true">删除</a>
                    </td>
                </tr>
            </table>
        </div>
        <!--撑满页面-->
        <div class="mini-fit">
            <div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 100%;" idfield="RowID"
                showfooter="false">
                <div property="columns">
                    <div type="indexcolumn" width="5%">
                    </div>
                    <div field="MailAddr" width="95%" headeralign="left" allowsort="false">
                        邮箱地址
                    </div>
                </div>
            </div>
        </div>
    </fieldset>
    <div style="text-align: center; padding: 10px;">
        <a class="mini-button" iconcls="icon-save" onclick="onOk" style="width: 60px; margin-right: 20px;">
            保存</a> <a class="mini-button" iconcls="icon-cancel" onclick="onCancel" style="width: 60px;">
                取消</a>
    </div>
    </form>
    <script type="text/javascript">
        mini.parse();
        var grid = mini.get("datagrid1");
        var form = new mini.Form("form1");
        var action;
        var ETypeCode;
        function CheckMail(mail) {
            var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if (filter.test(mail)) return true;
            else {
                mini.alert("您的邮箱地址格式不正确,请重新输入！");
                return false;
            }
        }
        function onKeyEnter() {
            add();
        }
        function add() {
            var data = grid.getData();
            var MailAddr = mini.getbyName("MailAddr").getValue();
            if (MailAddr == "") {
                mini.alert("请输入邮箱地址！");
                return;
            }
            if (CheckMail(MailAddr)) {
                for (var i = 0; i < data.length; i++) {
                    if (data[i].MailAddr == MailAddr) {
                        mini.alert(MailAddr + "已经存在了！");
                        return;
                    }
                }
                var data = { MailAddr: MailAddr };
                var json = mini.encode([data]);
                grid.addRow(data);
                mini.getbyName("MailAddr").setValue("");
            }
        }
        function removeRow() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                grid.removeRows(rows, true);
            }
            else {
                mini.alert("请选中一条您需要删除的记录!");
            }
        }
        function SaveData() {
            var o = {};
            o.ETypeCode = ETypeCode;
            var data = grid.getData();
            o.arrList = data;
            if (data.length > 0) {
                saveData(o, data);
            }
            else {
                mini.alert("请添加邮箱地址！");
            }
        }

        function saveData(o) {
            var json = mini.encode([o]);
            if (action == "edit") {
                $.ajax({
                    url: "../Service/BasicDataManageHandler.ashx?action=ModifyETypeMail",
                    data: { data: json },
                    type: 'POST',
                    success: function (text) {
                        CloseWindow("save");
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert(jqXHR.responseText);
                    }
                });
            }
            if (action == "new") {
                $.ajax({
                    url: "../Service/BasicDataManageHandler.ashx?action=AddETypeMail",
                    data: { data: json },
                    type: 'POST',
                    success: function (text) {
                        CloseWindow("save");
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert(jqXHR.responseText);
                    }
                });
            }
        }

        ////////////////////
        //标准方法接口定义
        function SetData(data) {
            action = data.action;
            data = mini.clone(data);
            ETypeCode = data.ETypeCode;
            if (action == "edit") {
                $.ajax({
                    url: "../service/BasicDataManageHandler.ashx?action=GetETypeMailListByETypeCode&ETypeCode=" + ETypeCode,
                    cache: false,
                    success: function (text) {
                        var o = mini.decode(text);
                        grid.setData(o);
                    }
                });
            }
        }

        function GetData() {
            var o = form.getData();
            return o;
        }
        function CloseWindow(action) {
            if (action == "close" && form.isChanged()) {
                if (confirm("数据被修改了，是否先保存？")) {
                    return false;
                }
            }
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();
        }

        function onOk() {
            SaveData();
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }
        

    </script>
</body>
</html>
